package com.wfm.media.controller;

import com.wfm.media.common.Result;
import com.wfm.media.dto.MacVodDTO;
import com.wfm.media.entity.MacVod;
import com.wfm.media.service.MacVodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/macvods")
public class MacVodController {

    @Autowired
    private MacVodService macVodService;

    /**
     * 视频列表查询
     */
    @GetMapping
    public Result<List<MacVodDTO>> list() {
        return Result.success(macVodService.listAll());
    }

    /**
     * 删除视频
     */
    @DeleteMapping("/{sourceId}/{vodId}")
    public Result<Void> delete(@PathVariable Integer sourceId, @PathVariable Integer vodId) {
        boolean success = macVodService.deleteByIds(sourceId, vodId);
        return success ? Result.success() : Result.error("删除失败");
    }

    /**
     * 添加视频
     */
    @PostMapping
    public Result<Void> add(@RequestBody MacVod macVod) {
        boolean success = macVodService.add(macVod);
        return success ? Result.success() : Result.error("添加失败");
    }

    /**
     * 根据源ID和视频ID查询
     */
    @GetMapping("/{sourceId}/{vodId}")
    public Result<MacVodDTO> getByIds(@PathVariable Integer sourceId, @PathVariable Integer vodId) {
        MacVodDTO macVodDTO = macVodService.getByIds(sourceId, vodId);
        return macVodDTO != null ? Result.success(macVodDTO) : Result.error("未找到相关视频");
    }

    /**
     * 根据源ID查询
     */
    @GetMapping("/{sourceId}")
    public Result<List<MacVodDTO>> getBySourceId(@PathVariable Integer sourceId) {
        List<MacVodDTO> macVodDTOs = macVodService.getBySourceId(sourceId);
        return Result.success(macVodDTOs);
    }

    /**
     * 修改视频
     */
    @PutMapping
    public Result<Void> update(@RequestBody MacVod macVod) {
        boolean success = macVodService.update(macVod);
        return success ? Result.success() : Result.error("修改失败");
    }
}